package com.multi.thread.chapter02.demo02;

/**
 *	线程锁的是对象
 *	1)、A线程先持有Object对象的Lock锁，B线程可以以异步的方式调用object对象的非synchronized类型的方法
 *	2)、A线程先持有Object对象的Lock锁，B线程如果在这时调用object对象中的synchronized类型的方法则需等待，也就是同步
 */
public class SychronizedMethodLockObject {
	
	synchronized public void methodA() {
		try {
			System.out.println("begin methodA threadName = " + Thread.currentThread().getName());
			Thread.sleep(5000);
			System.out.println("end time = " + System.currentTimeMillis());
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	synchronized public void methodB() {
		try {
			System.out.println("begin methodA threadName = " + Thread.currentThread().getName()
					+ ", begin time = " + System.currentTimeMillis());
			Thread.sleep(5000);
			System.out.println("end");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
